package com.zc.homePage.controller;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.StringUtils;
import com.zc.api.controller.APIController;
import com.zc.api.domain.ApsmsResult;
import com.zc.api.domain.TestDomain;
import com.zc.custom.domain.ChargeCustomOrderInfo;
import com.zc.custom.service.IChargeCustomOrderInfoService;
import com.zc.homePage.service.IHomePageService;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.List;

/**
 * @Author glb
 * @Date 2023/10/19 10:55
 * @Version 1.0
 */

@RestController
@RequestMapping("/homePage")
public class HomePageController {

    @Resource
    private IHomePageService homePageService;

    @Resource
    private IChargeCustomOrderInfoService chargeCustomOrderInfoService;//用户订单Service接口

    @Resource
    private APIController apiController;//用户订单Service接口

//    @GetMapping("/tretPriceTask")
//    public void tretPriceTask(String startTime, String endTime, String power, Long totalTime) throws Exception {
//        SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        String startTIme = startTime;
//        String endTIme = endTime;
//        ChargeCustomOrderInfo chargeCustomOrderInfo = new ChargeCustomOrderInfo();
//        chargeCustomOrderInfo.setStartTime(sd.parse(startTIme));
//        chargeCustomOrderInfo.setEndTime(sd.parse(endTIme));
//        chargeCustomOrderInfo.setPriceTypeCode("6cbf3548c7234a65af9dd165081c9537");
//        chargeCustomOrderInfo.setTotalPower(new BigDecimal(power));
//        chargeCustomOrderInfo.setTotalTime(totalTime);
//        try{
//            /*chargeCustomOrderInfo = */chargeCustomOrderInfoService.getOrderPriceDetails(chargeCustomOrderInfo);
//            System.out.println("");
//        }catch (Exception e){
//            e.printStackTrace();
//        }
//
//    }

    @GetMapping("/Test")
    public ApsmsResult Test(TestDomain testDomain) throws Exception {
//        apiController.query_equip_charge_status(String StartChargeSeq);
//        apiController.query_stations_info(String LastQueryTime, int PageNo, int PageSize);
        return apiController.query_start_charge(testDomain);
    }

    /**
     * 首页环比统计
     */
    @PreAuthorize("@ss.hasPermi('homePage:getLinkRelativeRatioCount')")
    @GetMapping(value = "/getLinkRelativeRatioCount")
    public AjaxResult getLinkRelativeRatioCount() {
        return AjaxResult.success(homePageService.getLinkRelativeRatioCount());
    }

    /**
     * 首页本周充电电量与使用次数分析
     */
    @PreAuthorize("@ss.hasPermi('homePage:getChargingCapacityChargingNumber')")
    @GetMapping(value = "/getChargingCapacityChargingNumber")
    public AjaxResult getChargingCapacityChargingNumber(@RequestParam(name = "timeType", required = false) String timeType) {
        if (StringUtils.isEmpty(timeType)) {
            return AjaxResult.error("时间类型为空！");
        }
        return AjaxResult.success(homePageService.getChargingCapacityChargingNumber(timeType));
    }

    /**
     * 首页本周充电桩使用率
     */
    @PreAuthorize("@ss.hasPermi('homePage:getChargingStationUsageRate')")
    @GetMapping(value = "/getChargingStationUsageRate")
    public AjaxResult getChargingStationUsageRate(@RequestParam(name = "timeType", required = false) String timeType) {
        if (StringUtils.isEmpty(timeType)) {
            return AjaxResult.error("时间类型为空！");
        }
        return AjaxResult.success(homePageService.getChargingStationUsageRate(timeType));
    }

    /**
     * 首页本周注册用户量
     */
    @PreAuthorize("@ss.hasPermi('homePage:getRegistrationVolume')")
    @GetMapping(value = "/getRegistrationVolume")
    public AjaxResult getRegistrationVolume() {
        return AjaxResult.success(homePageService.getRegistrationVolume());
    }

    /**
     * 首页今日各充电站充电电量
     */
    @PreAuthorize("@ss.hasPermi('homePage:getTodayStationSumPower')")
    @GetMapping(value = "/getTodayStationSumPower")
    public AjaxResult getTodayStationSumPower() {
        return AjaxResult.success(homePageService.getTodayStationSumPower());
    }


    /**
     * 首页今日充电订单
     */
    @PreAuthorize("@ss.hasPermi('homePage:getTodayChargeOrder')")
    @GetMapping(value = "/getTodayChargeOrder")
    public AjaxResult getTodayChargeOrder() {
        return AjaxResult.success(homePageService.getTodayChargeOrder());

    }
}
